home *** CD-ROM | disk | FTP | other *** search
- /*
- ** This is a viewer application shell
- **
- ** Nick Thompson, 1/31/96
- */
-
-
- /*------------------------------------------------------------*/
-
- /* always include this before anything else when using the QuickDraw 3D viewer */
- #include "QD3D.h"
-
- /* all we need is this header - to use the viewer */
- #include "QD3DViewer.h"
-
- /* this has the routines for renderer objects */
- #include "QD3DRenderer.h"
-
- /* this has the routines for view objects */
- #include "QD3DView.h"
-
- /* this header allows us to check for the viewer */
- #include <CodeFragments.h>
-
- #include <QuickDraw.h>
- #include <ColorPicker.h>
- /*------------------------------------------------------------*/
-
- /* convenience macros to peek at event records */
-
- #define HiWrd(aLong) (((aLong) >> 16) & 0xFFFF)
- #define LoWrd(aLong) ((aLong) & 0xFFFF)
-
-
- /*------------------------------------------------------------*/
-
- /* function prototypes for the application */
-
- void LoadMenuBarForApplication( short myMenuBarID ) ;
- void FatalAlert( short theErrorMessage ) ;
- void InitializeToolBox( void ) ;
- Boolean HasQuickDraw3DViewer( void ) ;
- Boolean SupportsAEVT( void ) ;
- void RegisterRequiredAppleEventHandlers( void ) ;
-
- pascal OSErr HandleCoreAppleEventOfTypeOAPP( AppleEvent *theAppleEvent,
- AppleEvent *theAppleEventReply,
- long userDefinedReferenceConstant) ;
-
- pascal OSErr HandleCoreAppleEventOfTypeODOC( AppleEvent *theAppleEvent,
- AppleEvent *theAppleEventReply,
- long userDefinedReferenceConstant) ;
-
- pascal OSErr HandleCoreAppleEventOfTypePDOC( AppleEvent *theAppleEvent,
- AppleEvent *theAppleEventReply,
- long userDefinedReferenceConstant) ;
-
- pascal OSErr HandleCoreAppleEventOfTypeQUIT( AppleEvent *theAppleEvent,
- AppleEvent *theAppleEventReply,
- long userDefinedReferenceConstant) ;
-
- void MainEventLoop( void ) ;
-
- void HandleKeyPress(EventRecord *theEventRecord) ;
- void HandleMenuCommand(long menuResult) ;
- void HandleAppleMenu( short menuItem ) ;
- void HandleFileMenu( short menuItem ) ;
- WindowPtr HandleFileNewItem( unsigned char *windowTitle ) ;
- OSErr HandleFileSaveAsItem( WindowPtr theWindow ) ;
- OSErr HandleFileSaveItem( WindowPtr theWindow ) ;
- OSErr HandleFileRevertItem( WindowPtr theWindow ) ;
- OSErr HandleFilePageSetupItem( WindowPtr theWindow ) ;
- OSErr HandleFilePrintItem( WindowPtr theWindow ) ;
- WindowPtr HandleFileOpenItem( FSSpec *theFSSpec ) ;
- OSErr HandleFileCloseItem( WindowPtr theWindow ) ;
- OSErr HandleFileQuitItem( void ) ;
- void HandleEditMenu( short menuItem ) ;
- void HandleRendererMenu( short menuItem ) ;
- void HandleViewMenu( short menuItem ) ;
-
- WindowPtr DoCreateNewViewerWindow( unsigned char *windowName ) ;
- Boolean PickViewerBackGroundColor(RGBColor *theRGBColor, unsigned char *thePrompt ) ;
- void AdjustMenus( void ) ;
- /*------------------------------------------------------------*/
-
- /* constants */
- const short kWindHeight = 250 ; /* default theWindow height */
- const short kWindWidth = 200 ; /* default theWindow width */
- const SFTypeList kTypeList = { '3DMF' } ; /* file type we can open */
- const short kNumTypes = 1 ; /* num of file types we can recognise */
-
- const short kAppMenuBarID = 128 ; /* resource ID for the application's menu bar */
- const short kFatalAlert = 128 ; /* res ID for error alert before we bail */
- const short kErrorAlertStrings = 128 ; /* res ID for alert strs */
- const short kAboutDialogID = 129; /* ID for the about box dialog */
-
- const short kInsetPixelsConst = 12 ; /* num of pixels to inset view by */
- /* error codes */
- enum {
- kNoMenuBar = 1,
- kNoQD3DViewerLib,
- kNoAEVTSupport
- } ;
-
- /* menu resource IDs */
- enum {
- mRendererMenu = 1, /* hierarchical, stored in the view menu */
- mAppleMenu = 128,
- mFileMenu,
- mEditMenu,
- mViewMenu
- } ;
-
- /* item numbers - Apple menu */
- enum {
- iAppleAboutItem = 1
- } ;
-
- /* item numbers - File menu */
- enum {
- iFileNewItem = 1,
- iFileOpenItem,
- iFileCloseItem = 4,
- iFileSaveItem,
- iFileSaveAsItem,
- iFileRevertItem,
- iFilePageSetupItem = 9,
- iFilePrintItem,
- iFileQuitItem = 12
- } ;
-
- /* item numbers - Edit menu */
- enum {
- iEditUndoItem = 1,
- iEditCutItem = 3,
- iEditCopyItem,
- iEditPasteItem,
- iEditClearItem = 7
- } ;
-
- /* item numbers - View menu */
- enum {
- iViewRendererItem = 1,
- iViewBadgeItem = 3,
- iViewCameraButtonItem = 5,
- iViewTruckButtonItem,
- iViewOrbitButtonItem,
- iViewZoomButtonItem,
- iViewDollyButtonItem,
- iViewInsetNFrameItem = 11,
- iViewSetBackgroundColorItem
- } ;
-
- /* item numbers - Renderer hierarchical menu */
- enum {
- iRendererInteractiveItem = 1,
- iRendererWireframeItem
- } ;
-
-
- /*------------------------------------------------------------*/
-
- /* type definitions */
-
- typedef struct {
-
- TQ3ViewerObject fViewer ; /* stores reference to the viewer object */
- FSSpec fFSSpec ; /* reference to the file for the document */
-
- } ViewerDocument, *ViewerDocumentPtr, **ViewerDocumentHdl ;
-
- /*------------------------------------------------------------*/
-
- /* global variables */
- Boolean gQuitFlag = false ; /* set to true to quit application */
- AEAddressDesc gSelfAddress; /* A self-addressed address descriptor record */
-
- /*------------------------------------------------------------*/
-
-
- void main(void)
- {
- InitializeToolBox() ;
- LoadMenuBarForApplication( kAppMenuBarID ) ;
-
- /*
- ** check that we have AppleEvents, and if so install the
- ** AppleEvent handlers for the required AppleEvents
- */
-
- if( SupportsAEVT() )
- {
- RegisterRequiredAppleEventHandlers() ;
-
- /*
- ** Check that the viewer is installed
- */
- if( HasQuickDraw3DViewer() )
- {
- MainEventLoop() ;
- }
- }
-
- ExitToShell();
-
- }
-
-
- /*------------------------------------------------------------*/
-
- /*
- ** Load the menu bar specified.
- */
-
- void LoadMenuBarForApplication( short myMenuBarID )
- {
- Handle menuBar = NULL;
-
- /*
- **Read menus into menu bar specified by the resource
- ** id passed into this routine by myMenuBarID
- */
- menuBar = GetNewMBar(myMenuBarID);
-
- if ( menuBar == NULL )
- ExitToShell();
-
- /* Install the menus we just read in */
- SetMenuBar(menuBar);
-
- /* it is now safe to dispose the menu handle */
- DisposeHandle(menuBar);
-
- /*
- ** this next routine adds the names of desk accessories
- ** to the specified menu, in this case the apple menu
- */
- AppendResMenu( GetMenuHandle( mAppleMenu ), 'DRVR' );
-
- /*
- ** now add the two hierarchical menus, one to
- ** select the renderer and one to select the
- ** the type of camera we are using
- */
- InsertMenu(GetMenu( mRendererMenu ), -1);
-
- /* call our routine to grey out menus as appropriate */
- AdjustMenus() ;
-
- /* finally ensure the new menubar gets drawn */
- DrawMenuBar();
- }
-
-
-
- /*------------------------------------------------------------*/
-
- /*
- ** Display an alert and quit.
- */
-
- void FatalAlert( short theErrorMessage )
- {
- unsigned char *thePString, theErrorStr[256] ;
-
- thePString = theErrorStr ;
-
- GetIndString( thePString, kErrorAlertStrings, theErrorMessage ) ;
- ParamText( thePString, "\p", "\p", "\p" ) ;
- StopAlert( kFatalAlert, NULL ) ;
- ExitToShell() ;
- }
-
- /*------------------------------------------------------------*/
-
- /*
- ** Initialize all the needed managers.
- */
-
- void InitializeToolBox( void )
- {
- /*
- ** Initialize the toolbox managers
- */
- InitGraf((Ptr)&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs((long)NULL);
- InitCursor();
-
- /*
- ** must call this so that the heap is expanded to maximum
- ** size before calling any viewer routines
- */
- MaxApplZone() ;
-
- }
-
- /*------------------------------------------------------------*/
-
- /*
- ** return true if the viewer is installed
- */
-
- Boolean HasQuickDraw3DViewer( void )
- {
- return((long) Q3ViewerNew != kUnresolvedCFragSymbolAddress) ;
- }
-
- /*------------------------------------------------------------*/
-
- /*
- ** returns true if the platform supports appleevents - we won't run
- ** if it doesn't
- */
- Boolean SupportsAEVT(void)
- {
- OSErr theError;
- long response;
-
- theError = Gestalt(gestaltAppleEventsAttr,&response);
- if (theError!=noErr)
- return false;
-
- return (response && (response << gestaltAppleEventsPresent));
- }
-
- /*------------------------------------------------------------*/
-
- /*
- ** called to register our AppleEvent handlers.
- **
- ** Should really have some error handling in here.
- */
- void RegisterRequiredAppleEventHandlers(void)
- {
- OSErr theError;
- ProcessSerialNumber myApplicationPSN; /* This application's psn */
-
- /* Set up a self-addressed descriptor record. */
- myApplicationPSN.highLongOfPSN = 0;
- myApplicationPSN.lowLongOfPSN = kCurrentProcess ;
-
- theError = AECreateDesc(typeProcessSerialNumber,
- (Ptr)&myApplicationPSN,
- sizeof(ProcessSerialNumber),
- &gSelfAddress);
- if (theError!=noErr)
- return;
-
- theError = AEInstallEventHandler( kCoreEventClass,
- kAEOpenApplication,
- NewAEEventHandlerProc(HandleCoreAppleEventOfTypeOAPP),
- 0L,
- false);
- if (theError!=noErr)
- return;
-
- theError = AEInstallEventHandler( kCoreEventClass,
- kAEOpenDocuments,
- NewAEEventHandlerProc(HandleCoreAppleEventOfTypeODOC),
- 0L,
- false);
- if (theError!=noErr)
- return;
-
- theError = AEInstallEventHandler( kCoreEventClass,
- kAEPrintDocuments,
- NewAEEventHandlerProc(HandleCoreAppleEventOfTypePDOC),
- 0L,
- false);
- if (theError!=noErr)
- return;
-
- theError = AEInstallEventHandler( kCoreEventClass,
- kAEQuitApplication,
- NewAEEventHandlerProc(HandleCoreAppleEventOfTypeQUIT),
- 0L,
- false);
- if (theError!=noErr)
- return;
- }
-
-
- /*------------------------------------------------------------*/
-
- /*
- ** open application theEventRecord handler for the core theEventRecord suite,
- ** by default we just want a blank new document
- */
- pascal OSErr HandleCoreAppleEventOfTypeOAPP( AppleEvent *theAppleEvent, AppleEvent *theAppleEventReply, long userDefinedReferenceConstant)
- {
- /*
- ** we don't actually do anything on open - you could,
- ** for example you might want to open a blank untitled
- ** theWindow
- */
- OSErr theError = noErr ;
- return theError;
- }
-
-
- /*------------------------------------------------------------*/
-
- /*
- ** handler for the open document AppleEvent handler
- */
-
- pascal OSErr HandleCoreAppleEventOfTypeODOC(AppleEvent *theAppleEvent, AppleEvent *theAppleEventReply, long userDefinedReferenceConstant)
- {
- FSSpec theFileSpec;
- AEDescList theDocumentList;
- OSErr theError,
- theIgnoredError;
- long myTempIndex,
- numberOfItemsInList;
- Size actualSize;
- AEKeyword theAEKeyword;
- DescType theDescriptorType;
-
-
- theError = AEGetParamDesc(theAppleEvent,keyDirectObject,typeAEList,&theDocumentList);
- if (theError == noErr) {
- /*
- ** see how many descriptor items are in the list
- ** this is the number of documents we want to open
- */
- theError = AECountItems(&theDocumentList,&numberOfItemsInList);
-
- /*
- ** now get each descriptor record from the list
- ** coerce the returned data to an FSSpec record, and
- ** open the asoociated file
- */
- for (myTempIndex=1; myTempIndex <= numberOfItemsInList && theError == noErr; myTempIndex++) {
-
- theError = AEGetNthPtr( &theDocumentList,
- myTempIndex,
- typeFSS,
- &theAEKeyword,
- &theDescriptorType,
- (Ptr)&theFileSpec,
- sizeof(theFileSpec),
- &actualSize);
-
- if (theError == noErr) {
-
- FInfo fndrInfo ;
-
- /*
- ** we now have a valid FSSpec to reference the file, we need to know
- ** what type the file is to determine which file open function to call
- ** we can determine this from the finder info for the file
- */
-
- theError = FSpGetFInfo( &theFileSpec, &fndrInfo );
-
- /*
- ** if we got that ok, then we switch on the file
- ** type (we don't care about the creator type)
- */
-
- if (theError == noErr) {
-
- switch( fndrInfo.fdType ) {
- case '3DMF':
- HandleFileOpenItem( &theFileSpec );
- break ;
- }
- }
- }
- }
- theIgnoredError = AEDisposeDesc(&theDocumentList);
- }
- return theError ;
- }
-
- /*------------------------------------------------------------*/
-
- /*
- ** handler for the print document theEventRecord handler
- */
- pascal OSErr HandleCoreAppleEventOfTypePDOC(AppleEvent *theAppleEvent,AppleEvent *theAppleEventReply,long userDefinedReferenceConstant)
- {
- FSSpec theFileSpec;
- AEDescList theDocumentList;
- OSErr theError;
- long myTempIndex,
- numberOfItemsInList;
- Size actualSize;
- AEKeyword theAEKeyword;
- DescType theDescriptorType;
-
-
- theError = AEGetParamDesc(theAppleEvent,keyDirectObject,typeAEList,&theDocumentList);
- if (theError == noErr) {
-
- /*
- ** see how many descriptor items are in the list
- ** this is the number of documents we want to print
- */
-
- theError = AECountItems(&theDocumentList,&numberOfItemsInList);
-
- /*
- ** now get each descriptor record from the list
- ** coerce the returned data to an FSSpec record, and
- ** print the asoociated file
- */
-
- for (myTempIndex=1; myTempIndex <= numberOfItemsInList && theError == noErr; myTempIndex++) {
-
- theError = AEGetNthPtr( &theDocumentList,
- myTempIndex,
- typeFSS,
- &theAEKeyword,
- &theDescriptorType,
- (Ptr)&theFileSpec,
- sizeof(theFileSpec),
- &actualSize);
-
- if (theError == noErr) {
-
- /*
- ** if the app handles printing then you could do
- ** something like: theError = HandlePrintDoc( &theFileSpec );
- */
-
- theError = errAEEventNotHandled ;
- }
- }
- theError = AEDisposeDesc(&theDocumentList);
- }
- return theError ;
- }
-
- /*------------------------------------------------------------*/
-
- /*
- ** Quit AppleEvent handler
- */
-
- pascal OSErr HandleCoreAppleEventOfTypeQUIT(AppleEvent *theAppleEvent,AppleEvent *theAppleEventReply,long userDefinedReferenceConstant)
- {
- OSErr theError = noErr ; /* this is used as the return value */
-
- theError = HandleFileQuitItem() ;
-
- return theError ;
- }
-
- /*------------------------------------------------------------*/
-
- /*
- ** we want to handle events until the fronmost theWindow goes away
- */
-
- void MainEventLoop( void )
- {
- EventRecord theEventRecord;
- WindowPtr theWindow;
- short thePart;
- Rect screenRect;
- Point aPoint = {100, 100};
- GrafPtr oldPort ;
- Boolean wasViewerEvent ;
- TQ3ViewerObject theViewer ;
-
-
-
- while( !gQuitFlag )
- {
- Point mouseLoc ;
-
- if (WaitNextEvent( everyEvent, &theEventRecord, GetCaretTime(), NULL ))
- {
-
- AdjustMenus() ;
-
- /*
- ** There is a bug in versions 1.0.4 and earlier of the Viewer,
- ** so the port has to be set and restored.
- */
- if(( theWindow = FrontWindow()) != NULL)
- {
- ViewerDocumentHdl theViewerDocumentHdl ;
- TQ3ViewerObject theViewer ;
-
- theViewerDocumentHdl = (ViewerDocumentHdl)GetWRefCon(theWindow) ;
- if(theViewerDocumentHdl != NULL)
- {
- if((theViewer = (**theViewerDocumentHdl).fViewer) != NULL)
- {
- GetPort( &oldPort ) ;
- SetPort((GrafPtr)theWindow ) ;
-
- wasViewerEvent = Q3ViewerEvent( theViewer, &theEventRecord );
- GetMouse( &mouseLoc ) ;
- Q3ViewerAdjustCursor( theViewer, &mouseLoc );
- SetPort( oldPort ) ;
- }
- }
-
- }
- else
- {
- wasViewerEvent = false ;
- }
-
- if( !wasViewerEvent )
- {
- SetCursor( &qd.arrow ) ;
- switch (theEventRecord.what)
- {
- case mouseDown:
-
- thePart = FindWindow( theEventRecord.where, &theWindow );
-
- switch( thePart ) {
- case inMenuBar:
- HandleMenuCommand(MenuSelect(theEventRecord.where));
- break;
-
- case inDrag:
-
- screenRect = (**GetGrayRgn()).rgnBBox;
- DragWindow( theWindow, theEventRecord.where, &screenRect );
- break ;
-
- case inContent:
-
- if (theWindow != FrontWindow())
- SelectWindow( theWindow );
- break ;
-
- case inGoAway:
- if (TrackGoAway( theWindow, theEventRecord.where )) {
- DisposeWindow ( theWindow );
- }
- break ;
-
- default:
- break ;
- }
- break ;
-
-
- case updateEvt:
-
- theWindow = (WindowPtr)theEventRecord.message;
- GetPort(&oldPort ) ;
- SetPort( theWindow );
-
- BeginUpdate( theWindow );
- {
- TQ3ViewerObject theViewer ;
- OSErr theErr ;
- ViewerDocumentHdl theViewerDocumentHdl ;
-
- theViewerDocumentHdl = (ViewerDocumentHdl)GetWRefCon(theWindow) ;
- if(theViewerDocumentHdl != NULL)
- {
- if((theViewer = (**theViewerDocumentHdl).fViewer) != NULL)
- {
- theErr = Q3ViewerDraw( theViewer );
- }
- }
- }
- EndUpdate( theWindow );
- SetPort( oldPort ) ;
- break ;
-
- case keyDown:
- case autoKey:
- HandleKeyPress(&theEventRecord);
- break;
-
- case diskEvt:
- if ( HiWrd(theEventRecord.message) != noErr )
- (void) DIBadMount(aPoint, theEventRecord.message);
- break;
-
- case osEvt:
- case activateEvt:
- break;
-
- }
- }
- }
- }
- }
-
-
- /*------------------------------------------------------------*/
-
- /*
- ** handle keydow events, all we do is dispatch to the
- ** menu handler if the command key is down, otherwise
- ** the keypress is ignored.
- */
-
- void HandleKeyPress(EventRecord *theEventRecord)
- {
- char key;
-
- key = theEventRecord->message & charCodeMask;
-
- /* check to see if we selected a menu */
- if ( theEventRecord->modifiers & cmdKey ) { /* Command key down? */
- HandleMenuCommand(MenuKey(key));
- }
- }
-
-
- /*------------------------------------------------------------*/
-
- /*
- ** handle menu commands
- */
-
- void HandleMenuCommand(long menuResult)
- {
- short menuID;
- short menuItem;
-
- menuID = HiWrd(menuResult);
- menuItem = LoWrd(menuResult);
-
- switch ( menuID ) {
-
- case mRendererMenu:
- HandleRendererMenu( menuItem ) ;
- break ;
-
- case mAppleMenu:
- HandleAppleMenu( menuItem ) ;
- break ;
-
- case mFileMenu:
- HandleFileMenu( menuItem ) ;
- break;
-
- case mEditMenu:
- HandleEditMenu( menuItem ) ;
- break ;
-
- case mViewMenu:
- HandleViewMenu( menuItem ) ;
- break ;
-
- }
- HiliteMenu(0); // Unhighlight whatever MenuSelect or MenuKey hilited
- }
-
- /*------------------------------------------------------------*/
-
- /*
- ** create a new viewer document window, this includes creating a
- ** document record, a window and an associated viewer object. the
- ** document record is stored in the window's refcon field, so it
- ** can be accessed as required via the window record.
- */
-
- WindowPtr DoCreateNewViewerWindow( unsigned char *windowName )
- {
- WindowPtr theWindow ;
- Rect myRect = { 0, 0, kWindHeight, kWindWidth } ;
- TQ3ViewerObject myViewer ;
- ViewerDocumentHdl myViewerDocument = NULL ;
-
- /* create a document record to hold the */
- /* data for this instance */
- myViewerDocument = (ViewerDocumentHdl)NewHandleClear(sizeof(ViewerDocument)) ;
-
- /* ideally we should stagger the rect */
- OffsetRect( &myRect, 50, 50 ) ;
-
- theWindow = NewCWindow( NULL,
- &myRect,
- windowName,
- true,
- documentProc,
- (WindowPtr)-1,
- true,
- 0L ) ;
-
- /* create the viewer object associated with this window */
- if((myViewer = Q3ViewerNew( (CGrafPtr)theWindow,
- &theWindow->portRect,
- kQ3ViewerDefault )) != NULL)
- {
- /* store a reference to the viewer in the document structure */
- (**myViewerDocument).fViewer = myViewer ;
-
- /* store a reference to the document structure in the refcon */
- /* field of the window */
- SetWRefCon( theWindow, (long)myViewerDocument ) ;
- }
- else
- {
- /* clean up any allocates storage and quit */
- if( myViewerDocument )
- DisposeHandle( (Handle)myViewerDocument ) ;
-
- if( theWindow )
- CloseWindow( theWindow ) ;
-
- theWindow = NULL ;
- }
-
- return theWindow ;
-
- }
-
- /*------------------------------------------------------------*/
-
- /*
- ** handle menu commands in the apple menu
- */
-
-
- void HandleAppleMenu( short menuItem )
- {
- Str255 daName;
- DialogPtr theDialog ;
- short itemHit ;
-
- switch ( menuItem ) {
- ModalFilterUPP theProc ;
-
- case iAppleAboutItem:
-
- theDialog = GetNewDialog ( kAboutDialogID, NULL, (WindowPtr)-1 );
-
- GetStdFilterProc( &theProc ) ;
- SetDialogDefaultItem(theDialog, ok) ;
-
-
- do {
- ModalDialog ( theProc, &itemHit );
- } while( itemHit != ok ) ;
- DisposDialog ( theDialog );
- break;
-
- default:
- GetItem(GetMHandle(mAppleMenu), menuItem, daName);
- (void) OpenDeskAcc(daName);
- break;
- }
- }
-
- /*------------------------------------------------------------*/
-
- /*
- ** handle menu commands in the file menu
- */
-
-
- void HandleFileMenu( short menuItem )
- {
- OSErr theError ;
- short theRef ;
- WindowPtr theWindow ;
- TQ3ViewerObject theViewer ;
- StandardFileReply theSFReply ;
- ViewerDocumentHdl theViewerDocumentHdl ;
- FSSpec theFSSpec ;
-
- switch ( menuItem ) {
-
- case iFileNewItem:
-
- HandleFileNewItem( "\pViewer Window" ) ;
- break ;
-
- case iFileSaveAsItem:
-
- if( (theWindow = FrontWindow()) != NULL )
- HandleFileSaveAsItem( theWindow ) ;
- break ;
-
- case iFileSaveItem:
- if( (theWindow = FrontWindow()) != NULL )
- HandleFileSaveItem( theWindow ) ;
- break ;
-
-
- case iFileRevertItem:
- if( (theWindow = FrontWindow()) != NULL )
- HandleFileRevertItem( theWindow ) ;
- break ;
-
- case iFilePageSetupItem:
- if( (theWindow = FrontWindow()) != NULL )
- HandleFilePageSetupItem( theWindow ) ;
- break ;
-
- case iFilePrintItem:
- if( (theWindow = FrontWindow()) != NULL )
- HandleFilePrintItem( theWindow ) ;
- break ;
-
- case iFileOpenItem:
-
- /* Get the file name to open */
- StandardGetFile( NULL, kNumTypes, kTypeList, &theSFReply ) ;
-
- /* did the user cancel? */
- if(theSFReply.sfGood)
- HandleFileOpenItem( &theSFReply.sfFile ) ; /* no - process the file */
-
- break ;
-
- case iFileCloseItem:
- if( (theWindow = FrontWindow()) != NULL )
- HandleFileCloseItem( theWindow ) ;
- break ;
-
- case iFileQuitItem:
- HandleFileQuitItem();
- break;
- }
-
- }
-
- /*------------------------------------------------------------*/
-
- /*
- ** handles the New menu item in the file menu
- */
-
-
- WindowPtr HandleFileNewItem( unsigned char *windowTitle )
- {
- WindowPtr theWindow ;
- theWindow = DoCreateNewViewerWindow( windowTitle ) ;
- return theWindow ;
- }
-
- /*------------------------------------------------------------*/
-
- /*
- ** handles the Save As menu item in the file menu
- */
-
-
- OSErr HandleFileSaveAsItem( WindowPtr theWindow )
- {
- OSErr theError = paramErr ;
- short theRef ;
-
- TQ3ViewerObject theViewer ;
- StandardFileReply theSFReply ;
- ViewerDocumentHdl theViewerDocumentHdl ;
- FSSpec theFSSpec ;
-
- /* this option can't be selected unless there is a frontwindow */
- /* the option is dimmed in adjustmenus if there is no window */
- if( theWindow != NULL ) /* sanity check */
- {
- theViewerDocumentHdl = (ViewerDocumentHdl)GetWRefCon(theWindow) ;
- if(theViewerDocumentHdl != NULL)
- {
- StandardPutFile("\pSave model as:", "\pUntitled", &theSFReply);
- if (theSFReply.sfGood)
- {
- theError = FSpOpenDF(&theSFReply.sfFile, fsWrPerm, &theRef);
- if (theError != noErr)
- {
- theError = FSpCreate(&theSFReply.sfFile, '????', '3DMF', theSFReply.sfScript);
- if (theError == noErr)
- theError = FSpOpenDF(&theSFReply.sfFile, fsCurPerm, &theRef);
- }
- if (theError == noErr)
- {
- (**theViewerDocumentHdl).fFSSpec = theSFReply.sfFile ;
- theViewer= (**theViewerDocumentHdl).fViewer ;
- theError = Q3ViewerWriteFile(theViewer, (long)theRef);
- theError = FSClose(theRef);
- }
-
- /* reset the window title */
- SetWTitle( theWindow, theSFReply.sfFile.name );
- }
- }
- }
- return theError ;
- }
-
- /*------------------------------------------------------------*/
-
- /*
- ** handles the Save menu item in the file menu
- */
-
-
- OSErr HandleFileSaveItem( WindowPtr theWindow )
- {
- OSErr theError = paramErr ;
- short theRef ;
-
- TQ3ViewerObject theViewer ;
- StandardFileReply theSFReply ;
- ViewerDocumentHdl theViewerDocumentHdl ;
- FSSpec theFSSpec ;
-
- /* this option can't be selected unless there is a frontwindow */
- /* the option is dimmed in adjustmenus if there is no window */
- if( theWindow != NULL ) /* sanity check */
- {
- theViewerDocumentHdl = (ViewerDocumentHdl)GetWRefCon(theWindow) ;
- if(theViewerDocumentHdl != NULL)
- {
- theFSSpec = (**theViewerDocumentHdl).fFSSpec ;
-
- /* open the file */
- theError = FSpOpenDF ( &theFSSpec, fsWrPerm, &theRef ) ;
- if( theError == noErr )
- {
- if((theViewer = (**theViewerDocumentHdl).fViewer) != NULL)
- {
- theError = Q3ViewerWriteFile( theViewer, (long)theRef );
- if( theError == noErr )
- theError = FSClose ( theRef ) ;
- }
- }
- }
- }
- return theError ;
-
- }
-
- /*------------------------------------------------------------*/
-
- /*
- ** handles the Revert menu item in the file menu
- */
-
-
- OSErr HandleFileRevertItem( WindowPtr theWindow )
- {
- OSErr theError = paramErr ;
- short theRef ;
-
- TQ3ViewerObject theViewer ;
- StandardFileReply theSFReply ;
- ViewerDocumentHdl theViewerDocumentHdl ;
- FSSpec theFSSpec ;
-
- /* this option can't be selected unless there is a frontwindow */
- /* the option is dimmed in adjustmenus if there is no window */
- if( theWindow != NULL ) /* sanity check */
- {
- theViewerDocumentHdl = (ViewerDocumentHdl)GetWRefCon(theWindow) ;
- if(theViewerDocumentHdl != NULL)
- {
- theFSSpec = (**theViewerDocumentHdl).fFSSpec ;
-
- /* open the file */
- theError = FSpOpenDF ( &theFSSpec, fsRdPerm, &theRef ) ;
- if( theError == noErr )
- {
- if((theViewer = (**theViewerDocumentHdl).fViewer) != NULL)
- {
- // Q3ViewerClear( theViewer ) ;
- theError = Q3ViewerUseFile( theViewer, (long)theRef );
- if( theError == noErr )
- theError = FSClose ( theRef ) ;
- }
- }
- }
- }
- Q3ViewerDraw( theViewer ) ;
- return theError ;
- }
-
- /*------------------------------------------------------------*/
-
- /*
- ** handles the Page Setup menu item in the file menu
- */
-
-
- OSErr HandleFilePageSetupItem( WindowPtr theWindow )
- {
- return noErr ;
- }
-
- /*------------------------------------------------------------*/
-
- /*
- ** handles the Print menu item in the file menu
- */
-
-
- OSErr HandleFilePrintItem( WindowPtr theWindow )
- {
- return noErr ;
- }
-
- WindowPtr HandleFileOpenItem( FSSpec *theFSSpec )
- {
- OSErr theError ;
- short theRef ;
- WindowPtr theWindow ;
- TQ3ViewerObject theViewer ;
- ViewerDocumentHdl theViewerDocumentHdl ;
-
- /* open the file */
- theError = FSpOpenDF( theFSSpec, fsRdPerm, &theRef ) ;
-
- if( theError == noErr )
- {
- theWindow = DoCreateNewViewerWindow( theFSSpec->name) ;
-
- if( theWindow != NULL )
- {
-
- theViewerDocumentHdl = (ViewerDocumentHdl)GetWRefCon(theWindow) ;
- if(theViewerDocumentHdl != NULL)
- {
- if((theViewer = (**theViewerDocumentHdl).fViewer) != NULL)
- {
- (**theViewerDocumentHdl).fFSSpec = *theFSSpec ;
- theError = Q3ViewerUseFile( theViewer, theRef );
- if( theError == noErr )
- theError = FSClose ( theRef ) ;
- }
- }
- }
- }
- return theWindow ;
- }
-
- /*------------------------------------------------------------*/
-
- /*
- ** handles the close menu item in the file menu
- ** close the window after disposing of the associated
- ** data structures (viewer, etc).
- */
-
-
- OSErr HandleFileCloseItem( WindowPtr theWindow )
- {
-
- OSErr theError = paramErr ;
- short theRef ;
-
- TQ3ViewerObject theViewer ;
- StandardFileReply theSFReply ;
- ViewerDocumentHdl theViewerDocumentHdl ;
- FSSpec theFSSpec ;
-
- /* this option can't be selected unless there is a frontwindow */
- /* the option is dimmed in adjustmenus if there is no window */
- if( theWindow != NULL ) /* sanity check */
- {
- theViewerDocumentHdl = (ViewerDocumentHdl)GetWRefCon(theWindow) ;
- if(theViewerDocumentHdl != NULL)
- {
- if((theViewer = (**theViewerDocumentHdl).fViewer) != NULL)
- {
- theError = Q3ViewerDispose( theViewer ) ;
- if( theError == noErr )
- DisposeWindow( theWindow ) ;
- }
- }
- }
- return theError ;
-
- }
-
- /*
- ** handles the Quit menu item in the file menu
- */
-
- OSErr HandleFileQuitItem( void )
- {
- OSErr theError = noErr ; /* this is used as the return value */
- WindowPtr theWindow ;
- Boolean tempQuitFlag = true ;
-
- /*
- ** if the application has any open windows, close them before
- ** tempQuitFlag. Since the user may cancelduring the process of
- ** closing, make sure we don't quit the app, unless they can
- ** be closed
- */
- while(( theWindow = FrontWindow()) != NULL && tempQuitFlag )
- tempQuitFlag = ( HandleFileCloseItem( theWindow ) == noErr) ;
-
-
- /*
- ** if we closed everything up successfully, return noErr, otherwise
- ** indicate to the caller of this function that we canceled
- */
-
- if (tempQuitFlag) {
- gQuitFlag = true; /* in other word the user didn't cancel */
- AEDisposeDesc(&gSelfAddress); /* don't forget to dispose of the */
- /* self-addressed descriptor. */
- }
- else {
- theError = userCanceledErr ;
- }
-
- return theError ;
-
- }
-
- /*------------------------------------------------------------*/
-
- /*
- ** handle menu commands in the edit menu
- */
-
-
- void HandleEditMenu( short menuItem )
- {
- ViewerDocumentHdl theViewerDocumentHdl ;
- WindowPtr theWindow ;
- TQ3ViewerObject theViewer ;
- OSErr theError ;
- theWindow = FrontWindow() ;
-
- if( theWindow != NULL )
- {
- /*
- ** get the reference to our viewer document data structure
- ** from the long reference constant for the window. Cast
- ** it to the appropriate type. If we can't get it (i.e. it's
- ** null we want to bail
- */
- theViewerDocumentHdl = (ViewerDocumentHdl)GetWRefCon(theWindow) ;
- if(theViewerDocumentHdl == NULL)
- return ;
-
- /* get the reference to the viewer object from our data structure */
- theViewer = (**theViewerDocumentHdl).fViewer ;
- if(theViewer == NULL)
- return ;
-
- switch ( menuItem )
- {
-
- case iEditUndoItem:
- /* we don't really support undo in this app */
- break ;
-
- case iEditCutItem:
- theError = Q3ViewerCut ( theViewer ) ;
- break ;
-
- case iEditCopyItem:
- theError = Q3ViewerCopy ( theViewer ) ;
- break ;
-
- case iEditPasteItem:
- theError = Q3ViewerPaste ( theViewer ) ;
- break ;
-
- case iEditClearItem:
- theError = Q3ViewerClear ( theViewer ) ;
- break ;
- }
- }
-
- }
-
- /*------------------------------------------------------------*/
-
- /*
- ** handle menu commands in the renderer menu
- */
-
-
- void HandleRendererMenu( short menuItem )
- {
- ViewerDocumentHdl theViewerDocumentHdl ;
- WindowPtr theWindow ;
- TQ3ViewerObject theViewer ;
- OSErr theError ;
- TQ3ViewObject myView ;
- TQ3Status myStatus ;
- TQ3RendererObject myRenderer ;
-
- theWindow = FrontWindow() ;
-
-
-
- if( theWindow != NULL )
- {
- /*
- ** get the reference to our viewer document data structure
- ** from the long reference constant for the window. Cast
- ** it to the appropriate type. If we can't get it (i.e. it's
- ** null we want to bail
- */
- theViewerDocumentHdl = (ViewerDocumentHdl)GetWRefCon(theWindow) ;
- if(theViewerDocumentHdl == NULL)
- return ;
-
- /* get the reference to the viewer object from our data structure */
- theViewer = (**theViewerDocumentHdl).fViewer ;
- if(theViewer == NULL)
- return ;
-
- switch ( menuItem )
- {
-
- /*
- ** These two items are contained in the Renderer
- ** sub-menu from the view menu
- */
- case iRendererWireframeItem:
- /* get an instance to a wireframe renderer object */
- myRenderer = Q3Renderer_NewFromType(kQ3RendererTypeWireFrame);
- break ;
-
- case iRendererInteractiveItem:
- /* get an instance to a interactive renderer object */
- myRenderer = Q3Renderer_NewFromType(kQ3RendererTypeInteractive);
- break ;
-
- default:
- /*
- ** if we got here there is something very wrong,
- ** so we'll just return
- */
- return ;
-
- }
- /*
- ** set the renderer for the view
- */
- myView = Q3ViewerGetView( theViewer );
- if( myView != NULL )
- {
- /* set the renderer to the one created in the switch statement above */
- myStatus = Q3View_SetRenderer(myView, myRenderer) ;
-
- /* now we have set the renderer we can dispose of the reference to it */
- myStatus = Q3Object_Dispose( myRenderer ) ;
-
- /* and redraw the content region of the viewer */
- theError = Q3ViewerDraw( theViewer ) ;
- }
- }
- }
-
-
-
-
-
-
- /*------------------------------------------------------------*/
-
- /*
- ** handle menu commands in the view menu
- */
-
-
- void HandleViewMenu( short menuItem )
- {
- ViewerDocumentHdl theViewerDocumentHdl ;
- WindowPtr theWindow ;
- TQ3ViewerObject theViewer ;
- OSErr theError ;
- unsigned long theViewerFlags;
- Rect theTmpRect ;
- GrafPtr savedPort ;
- RGBColor theRGBColor ;
- TQ3ColorARGB theViewerBGColor;
-
- theWindow = FrontWindow() ;
-
- if( theWindow != NULL )
- {
- /*
- ** get the reference to our viewer document data structure
- ** from the long reference constant for the window. Cast
- ** it to the appropriate type. If we can't get it (i.e. it's
- ** null we want to bail
- */
- theViewerDocumentHdl = (ViewerDocumentHdl)GetWRefCon(theWindow) ;
- if(theViewerDocumentHdl == NULL)
- return ;
-
- /* get the reference to the viewer object from our data structure */
- theViewer = (**theViewerDocumentHdl).fViewer ;
- if(theViewer == NULL)
- return ;
-
- /*
- ** since most of the items in this menu rely on adjusting
- ** the viewer flags, we'll get the flags here so we can
- ** bitwise manipulate them in the switch below
- */
- theViewerFlags = Q3ViewerGetFlags( theViewer ) ;
-
- switch ( menuItem )
- {
- /*
- ** the renderer item in this menu is handled
- ** by handlers for it's repective hierarchical
- ** menus, so we just need to handle the ones below
- */
-
- case iViewBadgeItem:
- /*
- ** this toggles the viewer bage and hides the
- ** vcontroller, clicking in the badge will
- ** hide the badge and show the controller
- */
- theViewerFlags ^= kQ3ViewerShowBadge;
- theViewerFlags ^= kQ3ViewerControllerVisible;
- break ;
-
- case iViewCameraButtonItem:
- theViewerFlags ^= kQ3ViewerButtonCamera ;
- break ;
-
- case iViewTruckButtonItem:
- theViewerFlags ^= kQ3ViewerButtonTruck ;
- break ;
-
- case iViewOrbitButtonItem:
- theViewerFlags ^= kQ3ViewerButtonOrbit ;
- break ;
-
- case iViewZoomButtonItem:
- theViewerFlags ^= kQ3ViewerButtonZoom ;
- break ;
-
- case iViewDollyButtonItem:
- theViewerFlags ^= kQ3ViewerButtonDolly ;
- break ;
-
- case iViewInsetNFrameItem:
- /*
- ** this toggles drawing the viewer slightly smaller
- **than the window. We key off the kQ3ViewerDrawFrame
- ** viewer flag - if it is set then we are already inset
- */
- theTmpRect = theWindow->portRect ;
- if( theViewerFlags & kQ3ViewerDrawFrame )
- {
- Q3ViewerSetBounds( theViewer, &theTmpRect ) ;
- }
- else
- {
- InsetRect( &theTmpRect, kInsetPixelsConst, kInsetPixelsConst ) ;
- Q3ViewerSetBounds( theViewer, &theTmpRect ) ;
- }
- theViewerFlags ^= kQ3ViewerDrawFrame ;
-
- GetPort( &savedPort ) ;
- SetPort( (GrafPtr)theWindow ) ;
- EraseRect( &theWindow->portRect ) ;
- SetPort( savedPort ) ;
-
- break ;
-
- case iViewSetBackgroundColorItem:
-
- Q3ViewerGetBackgroundColor(theViewer, &theViewerBGColor);
- theRGBColor.red = theViewerBGColor.r * 65535.0;
- theRGBColor.green = theViewerBGColor.g * 65535.0;
- theRGBColor.blue = theViewerBGColor.b * 65535.0;
-
- if(PickViewerBackGroundColor( &theRGBColor, "\pPick a viewer background color:" ))
- {
- theViewerBGColor.a = 1;
- theViewerBGColor.r = theRGBColor.red / 65535.0;
- theViewerBGColor.g = theRGBColor.green / 65535.0;
- theViewerBGColor.b = theRGBColor.blue / 65535.0;
- Q3ViewerSetBackgroundColor(theViewer, &theViewerBGColor);
- }
- break;
- }
- }
- Q3ViewerSetFlags( theViewer, theViewerFlags ) ;
- Q3ViewerDraw( theViewer ) ;
-
- }
-
- Boolean PickViewerBackGroundColor(RGBColor *theRGBColor, unsigned char *thePrompt )
- {
- ColorPickerInfo cpInfo;
- Boolean returnValue = false ;
-
- /* setting input color to be an RGB color */
- cpInfo.theColor.color.rgb.red = (*theRGBColor).red;
- cpInfo.theColor.color.rgb.blue = (*theRGBColor).blue;
- cpInfo.theColor.color.rgb.green = (*theRGBColor).green;
-
- cpInfo.theColor.profile = 0L;
-
- /* no colorsync destination profile */
- cpInfo.dstProfile = 0L;
-
- /* set the color picker flags */
- cpInfo.flags = AppIsColorSyncAware | CanModifyPalette |
- CanAnimatePalette;
-
- /* center dialog box on the deepest color screen */
- cpInfo.placeWhere = kDeepestColorScreen;
-
- /* use the system default picker */
- cpInfo.pickerType = 0L;
-
- /* install event filter and color-changed functions */
- cpInfo.eventProc = nil;
- cpInfo.colorProc = nil;
- cpInfo.colorProcData = 0L;
-
- /* sanity check */
- if( thePrompt[ 0 ] >= 255 )
- if( thePrompt[ 0 ] = 255 ) ;
-
- BlockMove( thePrompt, cpInfo.prompt, thePrompt[0] ) ;
-
- /* describe the Edit menu for Color Picker Manager */
- cpInfo.mInfo.editMenuID = mEditMenu ;
- cpInfo.mInfo.cutItem = iEditCutItem;
- cpInfo.mInfo.copyItem = iEditCopyItem;
- cpInfo.mInfo.pasteItem = iEditPasteItem;
- cpInfo.mInfo.clearItem = iEditClearItem;
- cpInfo.mInfo.undoItem = iEditUndoItem;
-
- /* display dialog box to allow user to choose a color */
- if(PickColor(&cpInfo) == noErr && cpInfo.newColorChosen)
- {
- /* use this new color */
- (*theRGBColor).red = cpInfo.theColor.color.rgb.red ;
- (*theRGBColor).blue = cpInfo.theColor.color.rgb.blue ;
- (*theRGBColor).green = cpInfo.theColor.color.rgb.green ;
-
- /* set up the return value */
- returnValue = cpInfo.newColorChosen ;
- }
-
- return returnValue ;
- }
-
-
- /*------------------------------------------------------------*/
-
- /*
- ** make sure that menus are enabled and disabled in an
- ** appropriate manner
- */
-
-
- void AdjustMenus( void )
- {
- MenuHandle theMenu ;
- ViewerDocumentHdl theViewerDocumentHdl ;
- WindowPtr theWindow ;
- TQ3ViewerObject theViewer ;
- TQ3ViewObject myView ;
- TQ3Status myStatus ;
- TQ3RendererObject myRenderer ;
- TQ3ObjectType theRendererType ;
- OSErr theError ;
- Rect theTmpRect ;
- GrafPtr savedPort ;
- long tmpLong, theScrapOffset ;
- unsigned long theViewerFlags;
- unsigned long theViewerState ;
-
- theWindow = FrontWindow() ;
-
-
- /* do we have a viewer theWindow open */
- if( theWindow != NULL ) {
-
- /* there is a theWindow, enable our menu commands */
-
- /*
- ** get the reference to our viewer document data structure
- ** from the long reference constant for the window. Cast
- ** it to the appropriate type. If we can't get it (i.e. it's
- ** null we want to bail
- */
- theViewerDocumentHdl = (ViewerDocumentHdl)GetWRefCon(theWindow) ;
- if(theViewerDocumentHdl == NULL)
- return ;
-
- /* get the reference to the viewer object from our data structure */
- theViewer = (**theViewerDocumentHdl).fViewer ;
- if(theViewer == NULL)
- return ;
-
- /* get the viewer state, we need to know if it is empty */
- theViewerState = Q3ViewerGetState( theViewer ) ;
-
- /* adjust the file menu */
- theMenu = GetMHandle ( mFileMenu ) ;
-
- EnableItem ( theMenu, iFileNewItem ); /* always enabled */
- EnableItem ( theMenu, iFileOpenItem ); /* always enabled */
- EnableItem ( theMenu, iFileQuitItem ); /* always enabled */
-
- EnableItem ( theMenu, iFileCloseItem );
-
- if( ((theViewerState & kQ3ViewerHasModel) ? true : false ) )
- {
- EnableItem ( theMenu, iFileSaveItem );
- EnableItem ( theMenu, iFileSaveAsItem );
- EnableItem ( theMenu, iFileRevertItem );
- EnableItem ( theMenu, iFilePageSetupItem );
- EnableItem ( theMenu, iFilePrintItem );
- }
- else
- {
- DisableItem ( theMenu, iFileSaveItem );
- DisableItem ( theMenu, iFileSaveAsItem );
- DisableItem ( theMenu, iFileRevertItem );
- DisableItem ( theMenu, iFilePageSetupItem );
- DisableItem ( theMenu, iFilePrintItem );
- }
-
-
- /* adjust the edit menu */
- theMenu = GetMHandle ( mEditMenu ) ;
-
- DisableItem ( theMenu, iEditUndoItem ); /* always disabled, no undo support in this app */
-
-
- if( ((theViewerState & kQ3ViewerHasModel) ? true : false ) )
- {
- EnableItem ( theMenu, iEditCutItem );
- EnableItem ( theMenu, iEditCopyItem );
- EnableItem ( theMenu, iEditClearItem );
- }
- else
- {
- DisableItem ( theMenu, iEditCutItem );
- DisableItem ( theMenu, iEditCopyItem );
- DisableItem ( theMenu, iEditClearItem );
- }
-
- /*
- ** check that there is some data that we can paste. GetScrap returns
- ** a long that gives either the length of the requested type, or a
- ** negative error code that is used to indicate that no such type exists
- */
-
- tmpLong = GetScrap( nil, '3DMF', &theScrapOffset ) ;
- if( tmpLong < 0 )
- DisableItem ( theMenu, iEditPasteItem );
- else
- EnableItem ( theMenu, iEditPasteItem );
-
-
-
- /* adjust the view menu */
- theMenu = GetMHandle ( mViewMenu ) ;
- EnableItem ( theMenu, 0L );
-
- /*
- ** since most of the items in this menu rely on adjusting
- ** the viewer flags, we'll get the flags here so we can
- ** bitwise manipulate them in the switch below
- */
- theViewerFlags = Q3ViewerGetFlags( theViewer ) ;
-
- /*
- ** check each of the items that have their flag
- ** bits set to true in the viewer flags.
- **
- ** Note that the Boolean flag for CheckItem is defined
- ** (( theViewerFlags & kQ3ViewerShowBadge ) ? true : false)
- ** and so on. The reson for this is that simply adding
- ** ( theViewerFlags & kQ3ViewerShowBadge ) won't be sufficient
- ** if the flag is the 8th bit or more of the unsigned long
- ** defined to hold the flages, since the param passed will
- ** only be the first 8 bits (of couse this is dependent on
- ** the develolment system size for Boolean, but this is true
- ** for CodeWarrior.
- */
-
- CheckItem( theMenu, iViewBadgeItem, (( theViewerFlags & kQ3ViewerShowBadge ) ? true : false)) ;
- CheckItem( theMenu, iViewCameraButtonItem, (( theViewerFlags & kQ3ViewerButtonCamera ) ? true : false)) ;
- CheckItem( theMenu, iViewTruckButtonItem, (( theViewerFlags & kQ3ViewerButtonTruck ) ? true : false)) ;
- CheckItem( theMenu, iViewOrbitButtonItem, (( theViewerFlags & kQ3ViewerButtonOrbit ) ? true : false)) ;
- CheckItem( theMenu, iViewZoomButtonItem, (( theViewerFlags & kQ3ViewerButtonZoom ) ? true : false)) ;
- CheckItem( theMenu, iViewDollyButtonItem, (( theViewerFlags & kQ3ViewerButtonDolly ) ? true : false)) ;
- CheckItem( theMenu, iViewInsetNFrameItem, (( theViewerFlags & kQ3ViewerDrawFrame ) ? true : false)) ;
-
- /* adjust the renderer menu */
- theMenu = GetMHandle ( mRendererMenu ) ;
-
- /*
- ** get the renderer for the view
- */
- myView = Q3ViewerGetView( theViewer );
- if( myView != NULL )
- {
- /* set the renderer to the one created in the switch statement above */
- myStatus = Q3View_GetRenderer(myView, &myRenderer) ;
- theRendererType = Q3Renderer_GetType( myRenderer ) ;
-
- CheckItem( theMenu, iRendererInteractiveItem, (theRendererType == kQ3RendererTypeInteractive)) ;
- CheckItem( theMenu, iRendererWireframeItem, (theRendererType == kQ3RendererTypeWireFrame)) ;
-
- /*
- ** getting the renderer incremented the ref count for it,
- ** we can dispose of the reference to it
- */
- myStatus = Q3Object_Dispose( myRenderer ) ;
-
- }
-
-
- }
- else {
-
- /* there is NOT a front window, disable most of our menu commands */
-
- /* adjust the file menu */
- theMenu = GetMHandle ( mFileMenu ) ;
-
- EnableItem ( theMenu, iFileNewItem ); /* always enabled */
- EnableItem ( theMenu, iFileOpenItem ); /* always enabled */
- EnableItem ( theMenu, iFileQuitItem ); /* always enabled */
-
- DisableItem ( theMenu, iFileCloseItem );
- DisableItem ( theMenu, iFileSaveItem );
- DisableItem ( theMenu, iFileSaveAsItem );
- DisableItem ( theMenu, iFileRevertItem );
- DisableItem ( theMenu, iFilePageSetupItem );
- DisableItem ( theMenu, iFilePrintItem );
-
- /* adjust the edit menu */
- theMenu = GetMHandle ( mEditMenu ) ;
-
- DisableItem ( theMenu, iEditUndoItem ); /* always disabled, no undo support in this app */
- DisableItem ( theMenu, iEditCutItem );
- DisableItem ( theMenu, iEditCopyItem );
- DisableItem ( theMenu, iEditPasteItem );
- DisableItem ( theMenu, iEditClearItem );
-
- /* disable the entire view menu if there is no window */
- theMenu = GetMHandle ( mViewMenu ) ;
- DisableItem ( theMenu, 0L );
-
- }
- DrawMenuBar() ;
- }
-
-
-